package eee.xiang.cloud_learning.config.datasource;

import io.shardingsphere.core.yaml.sharding.YamlShardingConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

/**
 * @author x-yin
 * @Date 2019/10/14
 */

//@Configuration
public class ShardDataSourceConfig {

    private YamlShardingConfiguration parse() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("");

        InputStreamReader inputStreamReader = new InputStreamReader(classPathResource.getInputStream(), Charset.defaultCharset());

        return new Yaml(new Constructor(YamlShardingConfiguration.class)).loadAs(inputStreamReader, YamlShardingConfiguration.class);
    }
}
